import {RequestRegister} from '../apis/index'
import {ref,type Ref} from 'vue'
import { useRouter } from 'vue-router'
import { Toast } from 'vant'
export const useRegister=()=>{
    //返回上一级
   const onClickLeft=()=>history.back()


   const username:Ref<string>=ref('')
   const password:Ref<string>=ref('')
   const headerimg:Ref<string>=ref('https://img2.baidu.com/it/u=2421090168,324781765&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1675875600&t=6540c7ab77cf7351ccaf3a4d59a79433')
   const router =useRouter()
   const onSubmit=async()=>{
    const data=await RequestRegister(username.value,password.value,headerimg.value)
    const {resultCode,resultInfo} =data
    if(resultCode===1){
        Toast({
            message: '注册成功',
            position: 'top',
          });         
          //跳转
        router.push('/login')

    }else{
      Toast({
        message: '用户已经注册',
        position: 'top',
      }); 
    }
   }
   //调用接口
   

   return {onClickLeft,password,username,onSubmit}
}